import MySQLdb;
from game.settings import *


def  serhSS(user,activ,has):
    db= MySQLdb.connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME);
    db.set_character_set('utf8')
    cursor= db.cursor();
    try:
      cursor.execute("""INSERT INTO a_game_gospeak(name,info) VALUES ('%s','%s')""" % (name,info) )
    except NameError:
      return 1
    return 0
def delActive(idf):
    db= MySQLdb.connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME);
    db.set_character_set('utf8')
    cursor= db.cursor();
    try:
      cursor.execute("DELETE FROM a_game_gospeak  WHERE id = %s " % (idf) );
    except NameError:
      return 1
    return 0

def ssesiondb(log,has,ip,ids):
   t=False
   db= MySQLdb.connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME);
   cursor= db.cursor();
   cursor.execute("SELECT username FROM auth_user  WHERE username = '%s'" % (nickname) );
   k=cursor.fetchall();
   for l in k:
       if  nickname ==l[0]:
        t=True
   return t

def SearchUser(nickname):
   t=False
   db= MySQLdb.connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME);
   cursor= db.cursor();
   cursor.execute("SELECT username FROM auth_user  WHERE username = '%s'" % (nickname) );
   k=cursor.fetchall();
   for l in k:
       if  nickname ==l[0]:
        t=True
   return t
def Searchemail(email2):
   t=False
   db= MySQLdb.connect(DATABASE_HOST,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME);
   cursor= db.cursor();
   cursor.execute("SELECT email FROM auth_user  WHERE email = '%s'" % (email2) );
   k=cursor.fetchall();
   for l in k:
      if  email2 ==l[0]: 
        t=True
   return t

   
